from utils.selenium.perform import WPerform, FindType
from selenium.webdriver.remote.webdriver import WebDriver, WebElement


def run(perform: WPerform, query: dict or list):
    """
    自定义执行
    :param perform:
    :param query: 带过来的参数
    :return:
    """
    # 点击到验证码登录
    userName = query.get('userName')
    code = query.get('code')
    nav_btn_element: WebElement = perform.fint(find_type=FindType.class_name, find_key='ant-tabs-tab', multiple=True,
                                               find_index=1)
    nav_btn_element.click()
    perform.sleep(2)
    username_element: WebElement = perform.fint(find_type=FindType.id, find_key='userName')
    username_element.send_keys(userName)

    code_element: WebElement = perform.fint(find_type=FindType.id, find_key='code')
    code_element.send_keys(code)
    perform.sleep(2)

    submit_element: WebElement = perform.fint(find_type=FindType.class_name,
                                              find_key='antd-pro-components-login-index-submit')
    submit_element.click()
    perform.driver.maximize_window()
    perform.sleep(3)
    perform.send_msg("最大化浏览器")

    # 发送自定义日志
    perform.send_msg('成功日志')

